<#import "/spring.ftl" as spring/>
<#import "html-macro.ftl" as h />
<#import "declaration-macro.ftl" as d />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>${d.declarationTypeName__}
        下单页面${d.isGeneralTrade__?string("---一般贸易",(d.isProcessTrade__?string("---加工贸易","---特殊贸易")))}</title>
    <link rel="stylesheet" type="text/css" href="http://static.bgext.com/css/jquery/jquery-ui-1.8.23.custom.css" media="screen">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/awesome/css/font-awesome.min.css" />"/>
<#--<link rel="stylesheet" type="text/css" href="<@spring.url "/semantic/semantic.css" />">-->
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/semantic/components/button.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/semantic/components/dropdown.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/semantic/components/form.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/semantic/components/grid.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "/semantic/components/icon.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/semantic/components/input.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/semantic/components/item.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/semantic/components/label.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/semantic/components/loader.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/semantic/components/menu.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/semantic/components/message.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/semantic/components/reset.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/semantic/components/search.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/semantic/components/segment.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/semantic/components/tab.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/semantic/components/table.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/semantic/components/transition.min.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/layer/skin/layer.css" />">
    <link rel="stylesheet" type="text/css"
          href="<@spring.url "http://static.bgext.com/css/order.css" />">
    <script type="text/javascript"
            src="<@spring.url "http://static.bgext.com/jquery-3.1.1.min.js" />"></script>
    <script type="text/javascript"
            src="<s:url value="http://static.bgext.com/js/jquery/jquery-ui-1.8.23.custom.min.js"/>"></script>
    <script type="text/javascript"
            src="<@spring.url "http://static.bgext.com/jquery.extend.js" />"></script>
<#--<script type="text/javascript" src="<@spring.url "/semantic/semantic.js" />"></script>-->
    <script type="text/javascript"
            src="<@spring.url "/semantic/components/form0.min.js" />"></script>
    <script type="text/javascript"
            src="<@spring.url "http://static.bgext.com/semantic/components/checkbox.min.js" />"></script>
    <script type="text/javascript"
            src="<@spring.url "http://static.bgext.com/semantic/components/tab.min.js" />"></script>
    <script type="text/javascript"
            src="<@spring.url "http://static.bgext.com/semantic/components/api.min.js" />"></script>
    <script type="text/javascript"
            src="<@spring.url "http://static.bgext.com/semantic/components/transition.min.js" />"></script>
    <script type="text/javascript"
            src="<@spring.url "http://static.bgext.com/semantic/components/dropdown.js" />"></script>
    <script type="text/javascript"
            src="<@spring.url "http://static.bgext.com/js/form/jquery.form.min.js"/>"></script>
    <script type="text/javascript"
            src="<@spring.url 'http://static.bgext.com/js/jquery/jquery-ui-1.8.23.custom.min.js'  />"></script>
    <script type="text/javascript"
            src="<@spring.url "http://static.bgext.com/layer/layer.js"/>"></script>
    <script type="text/javascript"
            src="<@spring.url "http://static.bgext.com/data-type.js"/>"></script>
    <script type="text/javascript"
            src="<@spring.url "http://static.bgext.com/dropdown.js"/>"></script>
    <script type="text/javascript"
            src="<@spring.url "http://static.bgext.com/dropdown-data.js"/>"></script>
    <script type="text/javascript"
            src="<@spring.url "/init.js"/>"></script>
    <script type="text/javascript"
            src="<@spring.url "/My97DatePicker/WdatePicker.js"/>"></script>
    <script type="text/javascript"
            src="<@spring.url "/pendingEntry-declaration.js"/>"></script>
    <script type="text/javascript"
            src="<@spring.url "http://static.bgext.com/js/queryAndUseModel.js"/>"></script>
    <#--<script type="text/javascript"
            src="<@spring.url "/declarationJumpConfig.js"/>"></script>-->
    <script type="text/javascript"
            src="<@spring.url "/pendingDeclarationJumpConfig.js"/>"></script>
    <script type="text/javascript"
            src="<@spring.url "http://static.bgext.com/elementJump.js"/>"></script>
    <script type="text/javascript"
            src="<@spring.url "http://static.bgext.com/js/jquery.AjaxPlugin.js"/>"></script>
    <script type="text/javascript"
            src="<@spring.url "http://static.bgext.com/js/layout.js"/>"></script>
    <script type="text/javascript"
            src="<@spring.url "/js/order.js"/>"></script>
<#--<script type="text/javascript" src="<@spring.url "/js/require.js"/>"
        data-main="<@spring.url "/js/main.js"/>" defer async="true"></script>-->
    <script type="text/javascript">
        var XLSX = {};
        $(document).ready(function () {
        <#if h.readMode__>
            readMode_readGoods_bind(); //绑定只读页面商品的查看
        </#if>
            $(window).on("unload", function (e) {
                var id = '${declaration.id}';
                if (id) {
                    $.ajax({
                               url: '/datalock/onUnlock.do?opaId=VDBS&bidId=${declaration.id}',
                               async: false
                           });
                }
            });
        });

        window.onbeforeunload = function (e) {
            var id = '${declaration.id}';
            if (id) {
                $.ajax({
                           url: '/datalock/onUnlock.do?opaId=VDBS&bidId=${declaration.id}',
                           async: false
                       });
            }
        };
        window.onunload = function (e) {
            var id = '${declaration.id}';
            if (id) {
                $.ajax({
                           url: '/datalock/onUnlock.do?opaId=VDBS&bidId=${declaration.id}',
                           async: false
                       });
            }
        };

    </script>
    <style type="text/css">
        .ui.relationTable {
            font-size: 12px;
            display: none;
        }

        .operate-relation-button {
            text-align: center !important;
        }

        .details-info-container {
            font-size: 14px;
            padding: 15px 20px;
            font-family: Arial, 'Microsoft YaHei';
        }

        .details-info-container div {
            padding-left: 36px;
        }

        .custom-broker-info {
            width: 90%;
        }

        .custom-broker-info tr {
            height: 30px;
            line-height: 30px;
        }

        .custom-broker-info .custom-label {
            text-align: right;
        }

        .details-info-fee {
            width: 90%;
            border-radius: 5px;
            border: 1px solid #000;
            margin-top: 7px;
            margin-bottom: 7px;
            margin-left: auto;
            margin-right: auto;
            text-align: center;
            /*font-weight: bold;*/

        }

        .details-info-fee .all-total {
            font-weight: bold;
        }

        .details-info-fee tr {
            height: 40px;
            line-height: 40px;
            padding: 15px 25px;
        }

        .loadLabelInputError {
            border-color: red !important;
        }

        .loadLabel-error-tips {
            color: red;
            font-size: 14px;
        }

        .nothing-price {
            text-align: center;
            font-size: 16px;
            font-weight: bold;
            line-height: 50px;
            height: 50px;
        }

        .fee-column-name {
            width: 10%;
        }

        .add-height {
            height: 50px !important;
        }

        .templateGoodsForm {
            display: none !important;
        }

        .compareTip {
            background-color: #ffff00 !important;
        }
        .lengthTips{
            font-size:14px;
        }
        .needRequired{
            color:red;
            display:none;
        }
        .warnTips{
            color:red;
        }
    </style>
</head>
<body>
<#if !d.isInsertPage__>
<div id="declaration_tabs" class="ui pointing secondary menu">
    <a class="active item">报关单基础信息</a>
<#--/business/business-declaration.do?id=f0fc943257a8660c0157a87155e30018-->
    <a class="item" data-tab="business-declaration">报关单</a>
<#--business/business-declarationPackingList.do?editType=1&id=f0fc943257a8660c0157a87155e30018-->
    <#if d.declarationType__>
        <a class="item" data-tab="business-declarationPackingList">装箱单</a>
    <#--/business/business-declarationContract.do?id=f0fc943257a8660c0157a87155e30018-->
        <a class="item" data-tab="business-declarationContract">合同</a>
    <#--/business/business-declarationInvoice.do?id=f0fc943257a8660c0157a87155e30018-->
        <a class="item" data-tab="business-declarationInvoice">发票</a>
    </#if>
<#--http://report.baigeonline.com/ReportServer?reportlet=gtimp/declarationPackingList_1.cpt&op=write&id=f0fc943257a8660c0157a87155e30018-->
    <a class="item" data-tab="business-declarationReport">导出报关资料</a>
    <#if d.isSanShuiJiBao__ || d.isFG__>
        <a class="item" data-tab="business-sanLianDanReport">导出三联单</a>
    </#if>
</div>
<div class="ui active tab segment" data-tab="first">
</#if>
<#if h.readMode__>
<#--只读模式-->
    <#include "order-button-read.ftl" />
</#if>
    <div class="ui grid " style="padding: 20px 20px">
    <#if !h.readMode__>
        <#include "pendingEntry-Order-Button.ftl" />
    </#if>
        <!--报关单主体信息-->
        <div class="ui eleven wide column">
            <input type="hidden" name="actionChain" value="${declaration.actionChain}"/>
        <#if d.declarationType__>
            <#include "pendingEntry-Order-Exportdeclaration.ftl" />
        <#else>
            <#include "order-Importdeclaration.ftl" />
        </#if>
        <#--<#include "order-declaration.ftl" />-->
        <#if pdfMode??>
            <div class="ui inline form segment">
                <div class="ui grid allform">
                    <div class="row">
                        <@h.label width="2" value="提交人" />
                            <@h.input width="3" value="${declaration.creator}" />
                            <@h.label width="2" value="提交时间" />
                            <@h.input width="3" value="${declaration.confirmTime?string('yyyy-MM-dd HH:mm:ss')}" />
                    </div>
                </div>
            </div>
        </#if>
        </div>
        <div class="five wide column">
        <#include  "order-container.ftl"/>
        </div>
    <#--用来显示表单验证提示-->
        <div class="errorMsgContainer">
            <div class="bg"></div>
            <div class="ui error message">
                <div class="modal-head">错误提示</div>
                <div class="modal-body"></div>
                <div class="modal-foot">
                    <button class="ui blue button closeError tiny">确定</button>
                </div>
            </div>
        </div>
        <div style="display: none;">
            <form id="declarationForm" method="post" action="<@spring.url "/order/save" />">
            </form>
        </div>
    </div>
<#if !d.isInsertPage__>
</div>
<div class="ui tab segment" data-tab="business-declaration">
    <#if h.readMode__>
    <#--只读模式-->
        <#include "order-supplier-button-read.ftl" />
    </#if>
    <iframe width="100%" frameborder="0" scrolling="no"
            src="<@spring.url "/business/business-declaration"/>?id=${declaration.id}&v=3.0">
    </iframe>
</div>
    <#if d.declarationType__>
    <div class="ui tab segment" data-tab="business-declarationPackingList">
        <#if h.readMode__>
        <#--只读模式-->
            <#include "order-supplier-button-read.ftl" />
        </#if>
        <iframe width="100%" frameborder="0" scrolling="no"
                src="<@spring.url "/business/business-declarationPackingList"/>?id=${declaration.id}&v=3.0"></iframe>
    </div>
    <div class="ui tab segment" data-tab="business-declarationContract">
        <#if h.readMode__>
        <#--只读模式-->
            <#include "order-supplier-button-read.ftl" />
        </#if>
        <iframe width="100%" frameborder="0" scrolling="no"
                src="<@spring.url "/business/business-declarationContract"/>?id=${declaration.id}&v=3.0"></iframe>
    </div>
    <div class="ui tab segment" data-tab="business-declarationInvoice">
        <#if h.readMode__>
        <#--只读模式-->
            <#include "order-supplier-button-read.ftl" />
        </#if>
        <iframe width="100%" frameborder="0" scrolling="no"
                src="<@spring.url "/business/business-declarationInvoice"/>?id=${declaration.id}&v=3.0"></iframe>
    </div>
    </#if>
<div class="ui tab segment" data-tab="business-declarationReport">


</div>

<div class="ui tab segment" data-tab="business-sanLianDanReport">


</div>
</#if>
</body>
<#--<script type="text/javascript"-->
<#--src="<@spring.url "/js/orderPolicyData.js"/>"></script>-->
<script type="text/javascript">

    var beforeSubmitValidate;
    /*
        * 下单时获取政策提醒
        * @source:input 的值
        * @key：要包含或者不包含的字符
        * 未完成任务项 后台正式接口 以及判断当前页面是哪一种交易类型页面*/
    function contain(source, key) {
        /*var reg = new RegExp("/^[" + key + "]+$/");*/
        var reg = new RegExp(key);
        /*if($.isNumeric(source)){
            source=parseFloat(source);
        }*/
        return reg.test(source);
    }

    function noContain(source, key) {
        /*var reg = new RegExp("/^[" + key + "]+$/");*/
        var reg = new RegExp(key);
        /*if($.isNumeric(source)){
            source=parseFloat(source);
        }*/
        return !reg.test(source);
    }

    var _POLICYWARN_ = {
        _init: function () {
            var _this = this;
            this.executeFunArr = [];
            $.ajax({
                       url: '/policyRules/order/policyData',
                       data: {"bizSence": _this._getSenceType},
                       /* data: {"bizSence": "rule_20170810032829923063"},*/
                       type: 'get',
                       dataType: 'json',
                       success: function (data) {
                           console.log(data);
                           if (data.result) {
                               _this.result = data.data;
                               console.log(_this.result);
                               for (var i = 0; i < _this.result.length; i++) {
                                   _this.elements = _this.result[i].elements;
                                   _this.expression = _this.result[i].expression;
                                   _this.notice = _this.result[i].notice;
                                   _this._bind(_this.elements, _this.expression, _this.notice, i);
                               }
                           } else {
                               /*layer.alert("获取下单政策提醒后台错误");*/
                               console.log("获取下单政策提醒后台错误");
                           }
                       },
                       error: function (a, b, c) {
                           console.log(b);
                       }
                   });
        },
        _executeFun: function (target, exp, msg, index) {
            var obj = {};
            obj.exp = exp;
            obj.msg = msg;
            obj.target = target;
            obj.index = index;
            return obj;
        },
        _getSenceType: function () {
            switch ("${d.declarationTypeName__}") {
                case "出口":
                <#if d.isGeneralTrade__>
                    this.bizSenceType = "EXN";
                </#if>
                <#if d.isProcessTrade__>
                    this.bizSenceType = "EXP";
                </#if>
                    break;
                case "进口":
                <#if d.isGeneralTrade__>
                    this.bizSenceType = "IMN";
                </#if>
                <#if d.isProcessTrade__>
                    this.bizSenceType = "IMP";
                </#if>
                    break;
            }
            return this.bizSenceType;
        },
        _isShowLayerTips: function (arg, $input) {
            var tipsNotice = "";
            var _this = this;
            if (arg.length > 1) {
                for (var i = 0; i < arg.length; i++) {
                    tipsNotice += arg[i].msg;
                }
            } else if (arg.length == 1) {
                tipsNotice = arg[0].msg;
            } else if (arg.length == 0) {
                $input.nextDeclarationInput({action: "next"});
            }
            /*this.enterCount++;*/
            if (tipsNotice != "") {
                this.layerAlertIndex = layer.alert(tipsNotice, function () {
                    _this.enterCount++;
                    layer.close(_this.layerAlertIndex);
                    $input.nextDeclarationInput({action: "next"});
                });
            } else {
                this.enterCount++;
            }

        },
        _bind: function (obj, expression, notice, index) {
            var _this = this;
            for (var i = 0; i < obj.length; i++) {
                (function (arg) {
                    if (/input\[name=/.test(obj[arg])) {
                        var index0 = obj[arg].indexOf("=");
                        var index1 = obj[arg].indexOf("]");
                        obj[arg] = obj[arg].substring(index0 + 2, index1 - 1);
                    }
                    _this.executeFunArr.push(_this._executeFun(obj[arg], expression, notice,
                                                               index));
                    /*console.log( _this.executeFunArr);*/
                    _this.enterCount = 0;
                    nextDeclarationConfig[obj[arg]] = {
                        action: "funCall", func: function ($input) {
                            var expArr = [];
                            _this.enterCount++;
                            $.each(_this.executeFunArr, function (m, n) {
                                var reg = new RegExp(obj[arg]);
                                if (reg.test(n.target)) {
                                    if (eval(n.exp)) {
                                        if (expArr.length) {
                                            $.each(expArr, function (o, p) {
                                                if (n.target != p.target) {
                                                    expArr.push(n);
                                                } else if (n.target == p.target && n.index
                                                                                   != p.index) {
                                                    expArr.push(n);
                                                }
                                            });
                                        } else {
                                            expArr.push(n);
                                        }

                                        /*var layerAlertIndex = layer.alert(n.msg, function () {
                                            layer.close(layerAlertIndex);
                                            $input.nextDeclarationInput({action: "next"});
                                        });*/
                                    }
                                    /*else {
                                                                           $input.nextDeclarationInput({action: "next"});
                                                                       }*/
                                }
                            });
                            _this._isShowLayerTips(expArr, $input);
                            if (window.event.keyCode == 13 && _this.enterCount % 2 == 0) {
                                layer.close(_this.layerAlertIndex);
                                $input.nextDeclarationInput({action: "next"});
                            }
                            /*if (eval(expression)) {
                                enterCount++;
                                var layerAlertIndex = layer.alert(notice, function () {
                                    layer.close(layerAlertIndex);
                                    $input.nextDeclarationInput({action: "next"});
                                });
                                if (window.event.keyCode == 13 && enterCount % 2 == 0) {
                                    layer.close(layerAlertIndex);
                                    $input.nextDeclarationInput({action: "next"});
                                }
                            } else {
                                $input.nextDeclarationInput({action: "next"});
                            }*/
                        }
                    };
                })(i);
            }
        }
    };
    var _IMPORTEXCEL = {
        _init: function () {
            this.allDropdownObj =
            ["transport_mode", "levymode", "goods_addr", "trade_mode"];
            this._setDropDownVal();
        },
        _setDropDownVal: function () {
            var _this = this;
            $.each(this.allDropdownObj, function (i, n) {
                var value = $("input[name='" + n + "']").val();
                $("input[name='" + n + "']").parent().dropdown("set selected", value);
            });
        }
    };
    var getDeclarationVal = function () {
        var obj = {};
        obj.bl_no = '${declaration.bl_no}';
        obj.company_co = '${declaration.company_co}';
        obj.fahuo_company_co = '${declaration.fahuo_company_co}';
        obj.transport_na = '${declaration.transport_na}';
        obj.voyage_no = '${declaration.voyage_no}';
        obj.arrived_country = '${declaration.arrived_country}';//运抵国是否要删除
        obj.arrived_country_code = '${declaration.arrived_country_code}';
        obj.arrived_port = '${declaration.arrived_port}';//指运港是否要删除
        obj.arrived_port_code = '${declaration.arrived_port_code}';
        obj.goods_addr = '${declaration.goods_addr}';//境内货源地是否要删除
        obj.goods_addr_code = '${declaration.goods_addr_code}';
        obj.other_goods_addr = '${declaration.other_goods_addr}';
        obj.deal_mode = '${declaration.deal_mode}';//成交方式是否要删除
        obj.goods_count = '${declaration.goods_count}';
        obj.goods_package = '${declaration.goods_package}';//包装种类是否要删除
        obj.net_weight = '${declaration.net_weight}';
        obj.remark = '${declaration.remark}';
        obj.trade_mode = '${declaration.trade_mode}';//监管方式是否要删除
        obj.trade_mode_code = '${declaration.trade_mode_code}';
        obj.company_name = '${declaration.company_name}';
        obj.transport_mode = '${declaration.transport_mode}';//运输方式是否要删除
        obj.fahuo_company_name = '${declaration.fahuo_company_name}';
        obj.levymode = '${declaration.levymode}';//征免性质是否要删除
        obj.levymode_code = '${declaration.levymode_code}';
        obj.contract_no = '${declaration.contract_no}';
        obj.gross_weight = '${declaration.gross_weight}';
        obj.customs_type = '${declaration.customs_type}';//报关单类型是否要删除
        obj.record_id = '${declaration.record_id}';
        obj.export_date =
        '${declaration.export_date?string('yyyy-MM-dd')}';
        obj.report_date =
        '${declaration.report_date?string('yyyy-MM-dd')}';
        obj.produce_factory = '${declaration.produce_factory}';
        obj.shenbao_company_co = '${declaration.shenbao_company_co}';
        obj.shenbao_company_name = '${declaration.shenbao_company_name}';
        obj.freight1 = '${declaration.freight1}';
        obj.freight2 = '${declaration.freight2}';
        obj.freight3 = '${declaration.freight3}';
        obj.premium1 = '${declaration.premium1}';
        obj.premium2 = '${declaration.premium2}';
        obj.premium3 = '${declaration.premium3}';
        obj.otherfee1 = '${declaration.otherfee1}';
        obj.otherfee2 = '${declaration.otherfee2}';
        obj.otherfee3 = '${declaration.otherfee3}';
        obj.re_manifest = '${declaration.re_manifest}';
        obj.re_record_id = '${declaration.re_record_id}';
        obj.re_jianguan = '${declaration.re_jianguan}';
        obj.re_yard_id = '${declaration.re_yard_id}';
        obj.export_port = '${declaration.export_port}';
        obj.export_port_code = '${declaration.export_port_code}';
        obj.tex_company = '${declaration.tex_company}';
        obj.license_no = '${declaration.license_no}';
        obj.suifudan = '${declaration.suifudan}';
        obj.suifudanValue = '${declaration.suifudanValue}';
        obj.ship_name = '${declaration.ship_name}';
        obj.state = '${declaration.state}';
        obj.enter_page='${declaration.enter_page}';
        obj.commodities = [];
    <#list declaration.commodities as cmmo>
        var storeGoodsObj = {};
        storeGoodsObj.id = '${(cmmo.id?length > 0)?string(cmmo.id,'')}';
        storeGoodsObj.index_num = '${cmmo.index_num}';
        storeGoodsObj.contractNumber = '${cmmo.contractNumber}';
        storeGoodsObj.record_id = '${cmmo.record_id}';
        storeGoodsObj.code_s = '${cmmo.code_s}';
        storeGoodsObj.code_t = '${cmmo.code_t}';
        storeGoodsObj.name = '${cmmo.name?js_string}';
        storeGoodsObj.key_elements = '${cmmo.key_elements?js_string}';
        storeGoodsObj.goods_mode = '${cmmo.goods_mode?js_string}';
        storeGoodsObj.count = '${cmmo.count}';
        storeGoodsObj.unitCode = '${cmmo.unitCode}';
        storeGoodsObj.unit = '${cmmo.unit}';
        storeGoodsObj.total_price = '${cmmo.total_price}';
        storeGoodsObj.unit_price = '${cmmo.unit_price}';
        storeGoodsObj.currencyCode = '${cmmo.currencyCode}';
        storeGoodsObj.currency = '${cmmo.currency}';
        storeGoodsObj.legal_count = '${cmmo.legal_count}';
        storeGoodsObj.legalUnitCode = '${cmmo.legalUnitCode}';
        storeGoodsObj.legal_unit = '${cmmo.legal_unit}';
        storeGoodsObj.destination = '${cmmo.destination}';
        storeGoodsObj.destination_code = '${cmmo.destination_code}';
        storeGoodsObj.origin_country = '${cmmo.origin_country}';
        storeGoodsObj.origin_country_code = '${cmmo.origin_country_code}';
        storeGoodsObj.levyModeCode = '${cmmo.levyModeCode}';
        storeGoodsObj.levymode = '${cmmo.levymode}';
        storeGoodsObj.second_count = '${cmmo.second_count}';
        storeGoodsObj.secondUnitCode = '${cmmo.secondUnitCode}';
        storeGoodsObj.second_unit = '${cmmo.second_unit}';
        storeGoodsObj.version_no = '${cmmo.version_no}';
        storeGoodsObj.goods_no = '${cmmo.goods_no}';
        storeGoodsObj.processing_fee = '${cmmo.processing_fee}';
        storeGoodsObj.package_type = '${cmmo.package_type}';
        storeGoodsObj.goods_gross_weight = '${cmmo.goods_gross_weight}';
        storeGoodsObj.goods_net_weight = '${cmmo.goods_net_weight}';
        storeGoodsObj.goods_number = '${cmmo.goods_number}';
        storeGoodsObj.packinglist_remark = '${cmmo.packinglist_remark}';
        obj.commodities.push(storeGoodsObj);
    </#list>
        obj.suiFuDans = [];
    <#list declaration.suiFuDans as sfd>
        var storeSuiFuObj = {};
        storeSuiFuObj.id = '${sfd.id}';
        storeSuiFuObj.suifudan_co = '${sfd.suifudan_co}';
        storeSuiFuObj.suifudan_no = '${sfd.suifudan_no}';
        obj.suiFuDans.push(storeSuiFuObj);
    </#list>
        obj.seller = '${declaration.seller}';
        obj.seller_address = '${declaration.seller_address}';
        obj.seller_phone = '${declaration.seller_phone}';
        obj.seller_fax = '${declaration.seller_fax}';
        obj.carton = '${declaration.carton}';
        obj.buyer = '${declaration.buyer?js_string}';
        obj.invoice_no = '${declaration.invoice_no}';
        obj.is_wood_packaging = '${declaration.is_wood_packaging}';
        obj.contract_remark = '${declaration.contract_remark}';
        obj.total_money = '${declaration.total_money}';
        obj.sum_count = '${declaration.sum_count}';
        obj.contract_date =
        '${declaration.contract_date?string('yyyy-MM-dd')}';
        obj.making_date =
        '${declaration.making_date?string('yyyy-MM-dd')}';
        obj.singing_place = '${declaration.singing_place}';
        obj.concrete_goods_package =
        '${declaration.concrete_goods_package}';
        obj.is_record_info = '${declaration.is_record_info}';
        obj.contract_terms_type = '${declaration.contract_terms_type}';
        obj.declaration_port = '${declaration.declaration_port}';
        obj.declaration_port_code =
        '${declaration.declaration_port_code}';
        obj.trading_country = '${declaration.trading_country}';
        obj.trading_country_code = '${declaration.trading_country_code}';
        obj.special_relationship_confirm =
        '${declaration.special_relationship_confirm}';
        obj.price_impact_confirm = '${declaration.price_impact_confirm}';
        obj.payment_royaltils_confirm =
        '${declaration.payment_royaltils_confirm}';
        obj.company_co_unite = '${declaration.company_co_unite}';
        obj.fahuo_company_co_unite =
        '${declaration.fahuo_company_co_unite}';
        obj.shenbao_company_co_unite =
        '${declaration.shenbao_company_co_unite}';
        obj.custom_time =
        '${declaration.custom_time?string('yyyy-MM-dd')}';
        obj.custom_status = '${declaration.custom_status}';
        obj.check_time = '${declaration.check_time?string('yyyy-MM-dd')}';
        obj.check_status = '${declaration.check_status}';
        obj.container_no = '${declaration.container_no}';
        obj.container_no_show = '${declaration.container_no_show}';
        obj.so = '${declaration.so}';
        obj.declaration_free = '${declaration.declaration_free}';
        obj.container_num = '${declaration.container_num}';
        obj.pay_id = '${declaration.pay_id}';
        obj.work_no = '${declaration.work_no}';
        obj.payment_type = '${declaration.payment_type}';
        obj.declaration_type = '${declaration.declaration_type}';
        obj.enter_page='${declaration.enter_page}';
        return obj;
    };
    var _COMPARE_ = {
        _init: function () {
            this.original = getDeclarationVal();
            this.useType = $("input[name=actionChain]").val();
            console.log(this.original);
            if (this.useType == "M3" || this.useType == "C3") {
                this._bind();
            }
        },
        _bind: function () {
            var _this = this;
            for (var prop in _this.original) {
                (function (target) {
                    if (target == "commodities") {
                        var markModifyIndex = [];
                        var markModifyObj = [];
                        for (var commoditiesProp in _this.original[target][0]) {
                            (function (commoditiesProp) {
                                var commoditiesPropOriginalVal;
                                if ($("#" + commoditiesProp).parent().hasClass("dropdown")) {
                                    $("#" + commoditiesProp).parent().on("click", function () {
                                        commoditiesPropOriginalVal = $("#" + commoditiesProp).val();
                                    });
                                }

                                $("#" + commoditiesProp).on("change", function () {
                                    var $indexNum = $("#index_num");
                                    if ($.inArray($indexNum.val(), markModifyIndex) == -1) {
                                        $("#commodities").find(".compareTip").removeClass("compareTip");
                                    } else {
                                        $("#commodities").find(".compareTip").removeClass("compareTip");
                                        $.each(markModifyObj, function (i, n) {
                                            if (n.index == $indexNum.val()) {
                                                if (n.target.parent().hasClass("dropdown")) {
                                                    n.target.parent().addClass("compareTip");
                                                } else {
                                                    n.target.addClass("compareTip");
                                                }
                                            }

                                        });
                                    }
                                    if ($indexNum.val() && _this.original[target].length
                                                           >= $indexNum.val()) {
                                        if ($(this).parent().hasClass("dropdown")) {
                                            var nextPrev = $(this).next().attr("id");
                                            if (_this.original[target][$indexNum.val()
                                                                       - 1][commoditiesProp] != ""
                                                && $(this).val()
                                                   != _this.original[target][$indexNum.val()
                                                                             - 1][commoditiesProp]) {
                                                markModifyIndex.push($indexNum.val());
                                                markModifyObj.push({
                                                                       index: $indexNum.val(),
                                                                       target: $(this)
                                                                   });
                                                $(this).parent().addClass("compareTip");
                                            } else if (_this.original[target][$indexNum.val()
                                                                              - 1][commoditiesProp]
                                                       == "" && commoditiesPropOriginalVal
                                                       && $(this).val()
                                                          != _this.original[target][$indexNum.val()
                                                                                    - 1][commoditiesProp]) {
                                                markModifyIndex.push($indexNum.val());
                                                markModifyObj.push({
                                                                       index: $indexNum.val(),
                                                                       target: $(this)
                                                                   });
                                                $(this).parent().addClass("compareTip");
                                            } else if (_this.original[target][$indexNum.val()
                                                                              - 1][commoditiesProp]
                                                       == "" && commoditiesPropOriginalVal == ""
                                                       && $(this).val() && $("#" + nextPrev).val()
                                                       && $("#" + nextPrev).val()
                                                          != _this.original[target][$indexNum.val()
                                                                                    - 1][nextPrev]) {
                                                markModifyIndex.push($indexNum.val());
                                                markModifyObj.push({
                                                                       index: $indexNum.val(),
                                                                       target: $(this)
                                                                   });
                                                $(this).parent().addClass("compareTip");
                                            }
                                        } else {
                                            if ($(this).val()
                                                != _this.original[target][$indexNum.val()
                                                                          - 1][commoditiesProp]) {
                                                markModifyIndex.push($indexNum.val());
                                                markModifyObj.push({
                                                                       index: $indexNum.val(),
                                                                       target: $(this)
                                                                   });
                                                $(this).addClass("compareTip");
                                                if (commoditiesProp == "count"
                                                    && $("#unitCode").val()
                                                       == $("#legalUnitCode").val()) {
                                                    $("#legal_count").addClass("compareTip");
                                                }
                                                if (commoditiesProp == "count"
                                                    && $("#unitCode").val() == "035") {
                                                    $("#goods_net_weight").addClass("compareTip");
                                                }
                                                if (commoditiesProp == "goods_net_weight"
                                                    && $("#unitCode").val() == "035"
                                                    && $("#unitCode").val()
                                                       == $("#legalUnitCode").val()) {
                                                    $("#legal_count").addClass("compareTip");
                                                    $("#count").addClass("compareTip");
                                                }
                                            }
                                        }
                                    }

                                });
                            })(commoditiesProp);
                        }
                    } else if (target == "suiFuDans") {
                        var markModifySuiFuObj = [];
                        for (var suifuProp in _this.original[target][0]) {
                            (function (suifuProp) {
                                var indexNum;
                                var suifuOriginalVal;
                                var $inputs = $("table[name=suifudanTable]").find("tbody input");
                                var $filterInputs;
                                var eventCount = 0;
                                var triggerEvent = false;
                                $filterInputs = $inputs.filter(function (index) {
                                    return ($($inputs[index]).val() != "");
                                });
                                if ($("#" + suifuProp).parent().hasClass("dropdown")) {
                                    $("#" + suifuProp).parent().on("click", function () {
                                        console.log("一次");
                                        suifuOriginalVal = $("#" + suifuProp).val();
                                        triggerEvent = true;
                                        eventCount++;
                                    })
                                } else {
                                    $("#" + suifuProp).on("focus", function () {
                                        suifuOriginalVal = $(this).val();
                                        triggerEvent = true;
                                    });
                                }
                                $("#" + suifuProp).on("change", function () {
                                    if (eventCount == 2) {
                                        triggerEvent = false;
                                    }
                                    var _this_ = this;
                                    $("#suiFuDans").find(".compareTip").removeClass("compareTip");
                                    if (!triggerEvent) {
                                        $.each(markModifySuiFuObj, function (j, k) {
                                            if ($(_this_).val() == k.relateValue && $(_this_).val()
                                                                                    == k.currentValue
                                                && k.suiFuDanNoValue) {
                                                $("#suiFuDans").find(".compareTip").removeClass("compareTip");
                                                k.relateTarget.parent().addClass("compareTip");
                                                return false;
                                            } else if ($(_this_).val() == k.relateValue
                                                       && $(_this_).val() != k.currentValue
                                                       && k.currentValue == k.suiFuDanNoValue) {
                                                $("#suiFuDans").find(".compareTip").removeClass("compareTip");
                                                k.suiFuDanNoTarget.addClass("compareTip");
                                                return false;
                                            } else if ($(_this_).val() == k.suiFuDanNoValue
                                                       && $(_this_).val() == k.currentValue
                                                       && k.relateValue) {
                                                $("#suiFuDans").find(".compareTip").removeClass("compareTip");
                                                k.suiFuDanNoTarget.addClass("compareTip");
                                                return false;
                                            }
                                        });
                                        return;
                                    }
                                    $.each($filterInputs, function (j, k) {
                                        if ($(this).val() == suifuOriginalVal) {
                                            var indexPattern = /\[\d+\]/;
                                            indexNum =
                                            $(this).attr("name").match(indexPattern)[0].replace("[",
                                                                                                "").replace("]",
                                                                                                            "");
                                            ;
                                            return false;
                                        }
                                    });
                                    if (indexNum && $(this).val() && $(this).val()
                                                                     != _this.original[target][indexNum][suifuProp]) {
                                        if ($(this).parent().hasClass("dropdown")) {
                                            $(this).parent().addClass("compareTip");
                                            markModifySuiFuObj.push({
                                                                        suiFuDanNoTarget: $(this).parent().next().next().find("input"),
                                                                        suiFuDanNoValue: $(this).parent().next().next().find("input").val(),
                                                                        relateTarget: $(this),
                                                                        relateValue: $(this).val(),
                                                                        currentTarget: $(this),
                                                                        currentValue: $(this).val()
                                                                    });
                                        } else {
                                            $(this).addClass("compareTip");
                                            markModifySuiFuObj.push({
                                                                        suiFuDanNoTarget: $(this),
                                                                        suiFuDanNoValue: $(this).val(),
                                                                        relateTarget: $(this).parent().prev().prev(".dropdown").find("input").eq(0),
                                                                        relateValue: $(this).parent().prev().prev(".dropdown").find("input").eq(0).val(),
                                                                        currentTarget: $(this),
                                                                        currentValue: $(this).val()
                                                                    });
                                        }

                                    }
                                });
                            })(suifuProp);
                        }
                    } else {
                        var $target = $("input[name=" + target + "]");
                        if ($target.parent().hasClass("dropdown")) {
                            if (!(/code/.test(target)) && $target.prev().length) {
                                $target.prev().on("change", function () {
                                    $(this).parent().addClass("compareTip");
                                });
                            } else {
                                $target.on("change", function () {
                                    $(this).parent().addClass("compareTip");
                                    /*if(target=="company_co"||target=='fahuo_company_co'){
                                       $("input[name=company_name]").addClass("compareTip");
                                        $("input[name=fahuo_company_name]").addClass("compareTip");
                                    }*/
                                });
                            }
                        } else {
                            if (target == "export_date" || target == "contract_date") {
                                var timeClickCount = 0;
                                $("input[name=" + target + "]").on("focus", function () {
                                    timeClickCount++;
                                    if (timeClickCount % 2 == 0) {
                                        if ($(this).val() != _this.original[target]) {
                                            $(this).addClass("compareTip");
                                        }
                                    }
                                });
                            }
                            $target.on("change", function () {
                                if ($(this).val() != _this.original[target]) {
                                    if (target == "is_wood_packaging") {
                                        $(this).parent().addClass("compareTip");
                                    } else {
                                        $(this).addClass("compareTip");
                                    }
                                    if (target == "contract_no") {
                                        $("input[name=invoice_no]").addClass("compareTip");
                                    }
                                }
                            });
                        }
                    }
                })(prop);
            }
        }
    };

    $(document).ready(function () {
        //当暂存后有运抵国，但是没有商品项时，自动关联运抵国到目的国
        $("#destination_code").parent().dropdown("set selected", $("input[name=arrived_country_code]").val());
        _IMPORTEXCEL._init();
        _COMPARE_._init();
        $("input[name='container_num']").blur(function () {
            requestSupCompniesInfo._init();
        });
        $("input[name='goods_item_num']").blur(function () {
            requestSupCompniesInfo._init();
        });
        $("a[data-tab='business-declarationReport']").click(function () {
            var htmlStr;
        <#if d.declarationType__>
            htmlStr =
            "<iframe width=\"100%\" height=\"800px\" frameborder=\"0\" scrolling=\"no\" src=\"http://report.baigeonline.com/ReportServer?reportlet=gtimp/declarationPackingList_1.cpt&op=write&id=${declaration.id}\"></iframe>";
        <#else>
            htmlStr =
            "<iframe width=\"100%\" height=\"800px\" frameborder=\"0\" scrolling=\"no\" src=\"http://report.baigeonline.com/ReportServer?reportlet=gtimp/declarationPackingList_2.cpt&op=write&id=${declaration.id}\"></iframe>";
        </#if>
            $("div[data-tab='business-declarationReport']").html(htmlStr);
        });
    <#if d.isSanShuiJiBao__>
        $("a[data-tab='business-sanLianDanReport']").click(function () {
            var htmlStr;

            htmlStr =
            "<iframe width=\"100%\" height=\"800px\" frameborder=\"0\" scrolling=\"no\" src=\"http://report.baigeonline.com/ReportServer?reportlet=gtimp/triplicate-sanshui.cpt&did=${declaration.id}&__filename__=三联单(${declaration.businessId})\"></iframe>";

            $("div[data-tab='business-sanLianDanReport']").html(htmlStr);
        });
    </#if>
    <#if d.isFG__>
        $("a[data-tab='business-sanLianDanReport']").click(function () {
            var htmlStr;

            htmlStr =
            "<iframe width=\"100%\" height=\"800px\" frameborder=\"0\" scrolling=\"no\" src=\"http://report.baigeonline.com/ReportServer?reportlet=gtimp/triplicate-fogang.cpt&did=${declaration.id}&__filename__=三联单(${declaration.businessId})\"></iframe>";

            $("div[data-tab='business-sanLianDanReport']").html(htmlStr);
        });
    </#if>
    })
    ;
    <#if d.isSupplierPage__>
    $(document).ready(function () {
        $(".button-line").remove();
        $("button[_id='returnBtn']").one('click', function () {
            $("button#returnBtn").click();
        });
        $("button[_id='toValidBtn']").one('click', function () {
            $("button#toValidBtn").click();
        });
        $("button[_id='toRejectBtn']").one('click', function () {
            $("button#toRejectBtn").click();
        });
        //查看编辑报关单资料
        $("button[_id='uploadDeclarationAttachmentBtn']").one('click', function () {
            $("button#uploadDeclarationAttachmentBtn").click();
        });
        var cabinetLen = $("table[name=containerTable]").find("tbody tr").length;
        var $divGrossWeight;
        $("div.ui.label").each(function (i, n) {
            if ($(this).text() == "毛重(KG)") {
                $divGrossWeight = $(this);
                return false;
            }
        });
        if (cabinetLen && (parseInt($divGrossWeight.next().text()) / 1000 > 28 * cabinetLen)) {
            layer.alert("该票单超出了限载重量");
        }
    });
    </#if>

    //页面错误弹出窗口提示，现导入模板在使用
    var errorMsg;
    <#if errorMsg??>
    errorMsg = '${errorMsg}';
    layer.alert(errorMsg);
    </#if>

</script>
</html>
